package com.example.seckilldemo.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

/**
 * @Author Wangbaba
 * @Date 2024/3/16 19:20
 * @Version 1.0
 */
@Component
public class MD5Utils {

    public static final String salt="1a5f3sd";

    public static final String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    //一次加密
    public static String inputPassToFromPass(String inputPass){
        String str=""+salt.charAt(1)+salt.charAt(2)+inputPass+salt.charAt(4)+salt.charAt(6);
        return md5(str);
    }

    //二次加密
    public static String formPassToDBPass(String formPass,String salt){
        String str=salt.charAt(0)+salt.charAt(3)+formPass+salt.charAt(1);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass,String salt){
        String formPass=inputPassToFromPass(inputPass);
        String dbPass=formPassToDBPass(formPass,salt);
        return dbPass;
    }

    public static void main(String[] args) {
        System.out.println(inputPassToFromPass("yang1999"));
        System.out.println(formPassToDBPass("c6f86ffb26c9fbb3072f9349a98143f8","1a5f3sd"));
        System.out.println(inputPassToDBPass("yang1999","1a5f3sd"));
    }
}
